package com.forwknow.testmabatis;
//输入流对文件进行读操作

import com.foreknow.bean.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.Date;

/**
 * Junit测试类
 */
public class TestUser {


    @Test

    public void updateByIdTest() throws IOException {
        String resourse = "SqlMapConfig.xml";
        //如何对SqlMapConfig.xml读取并解析
        //Ctrl看返回值类型
        InputStream inputStream = Resources.getResourceAsStream(resourse);
        //获取会话工厂SqlsessionFactory
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
//       SqlSession主要用于对数据库的操作
        SqlSession session = sessionFactory.openSession();
//     修改
        User user = new User();
        user.setUsername("ashdufio");
        user.setId(22);
        session.update("test.updateById", user);
        session.commit();
        session.close();

    }

}

